package cn.pink.centersrv;

import cn.pink.common.support.tools.cache.CacheTool;
import cn.pink.core.Port;
import cn.pink.core.Service;
import cn.pink.core.support.Log;
import cn.pink.core.support.SysException;

/**
 * @Author: pink
 * @Date: 2022/11/17 12:24
 */
public class CenterPort extends Port {
    public CenterPort(String portId) {
        super(portId);
    }

    /**
     * 覆写父类函数
     * 增加防ID重复的判断机制
     */
    @Override
    public void addService(Service service) {
        //先检查一下此ID之前是否已经添加过 避免由于ID冲突造成隐藏的BUG
        Service serv = getService(service.getId());
        if (serv != null) {
            throw new SysException("Port添加下属服务时发送重复的号码：ID={}", service.getId());
        }

        super.addService(service);
    }

    public void cacheLoad() {
        CacheTool.getInstance().load().onSuccess(v -> Log.center.info("加载缓存完毕"));
    }
}
